/******************************************************************************
 *  Date:
 *      March 2011
 *
 *  Authors:
 *      Tomasz Jankowski 171073
 * 		Marcin Wojciechowski, 181057
 *
 *  Puprose:
 *      An academic project on Univercity of technologi in Wroclaw.
 *
 ******************************************************************************/

#include <cstdio>
#include <cstdlib>

#include "graph_generator.hpp"
#include "heap.hpp"

int main (int argc, char *argv[])
{
    if (argc != 5)
    {
        return -1;
    }
    
    int algorithm (atoi (argv [1]));
    int iterations (atoi (argv [2]));
    int nodes (atoi (argv [3]));
    int edges (atoi (argv [4]));
    int i (0);
    
    printf ("Nodes: %d, edges: %d\n", nodes, edges);

////////////////////////////////////////////////////////////////////////////////         
#ifdef VERBOSE   
    printf ("Graf skierowany w postaci macierzy incydencji:\n");
#endif // VERBOSE
    fflush (0);

    if (algorithm == 0)
    {
        OrientedIncidenceMatrix oriented_graph_matrix (nodes, edges);
        
        oriented_graph_matrix.generate (1, 10);    
#ifdef VERBOSE     
        oriented_graph_matrix.print ();
#endif // VERBOSE
        
        printf ("Najkrotsza scizka (algorytm Dijkstry, macierz):\n");
        for (i = 0; i < iterations; i++)
        {
            oriented_graph_matrix.find_shortest_path_dijkstra (0);  
        }
    }

    if (algorithm == 1)
    {    
        OrientedIncidenceMatrix oriented_graph_matrix (nodes, edges);
        
        oriented_graph_matrix.generate (1, 10);    
#ifdef VERBOSE     
        oriented_graph_matrix.print ();
#endif // VERBOSE
        
        printf ("Najkrotsza scizka (algorytm Bellman-Ford, macierz):\n");
        for (i = 0; i < iterations; i++)
        {
            oriented_graph_matrix.find_shortest_path_bellman_ford (0); 
        }
    }
    
////////////////////////////////////////////////////////////////////////////////        
#ifdef VERBOSE     
    printf ("Graf nieskierowany w postaci macierzy incydencji:\n");
#endif // VERBOSE
    fflush (0);
    
    if (algorithm == 2)
    {     
        UnorientedIncidenceMatrix unoriented_graph_matrix (nodes, edges);
        
        unoriented_graph_matrix.generate (1, 10);    
#ifdef VERBOSE     
        unoriented_graph_matrix.print ();
#endif // VERBOSE
        
        printf ("Drzewo rozpinajace (Kruskal, macierz)\n");
        for (i = 0; i < iterations; i++)
        {
            unoriented_graph_matrix.get_spanning_tree_kruskal ();     
        }
    }
        
    if (algorithm == 3)
    {      
        UnorientedIncidenceMatrix unoriented_graph_matrix (nodes, edges);
        
        unoriented_graph_matrix.generate (1, 10);    
#ifdef VERBOSE     
        unoriented_graph_matrix.print ();
#endif // VERBOSE
        
        printf ("Drzewo rozpinajace (Prim, macierz)\n");
        for (i = 0; i < iterations; i++)
        {
            unoriented_graph_matrix.get_spanning_tree_prim ();     
        }
    }
    
//////////////////////////////////////////////////////////////////////////////// 
#ifdef VERBOSE     
    printf ("Graf skierowany w postaci listy sasiedztwa:\n");
#endif // VERBOSE
    fflush (0);

    if (algorithm == 4)
    {      
        OrientedAdjacencyList oriented_graph_list (nodes, edges);
        
        oriented_graph_list.generate (1, 10);       
#ifdef VERBOSE     
        oriented_graph_list.print ();
#endif // VERBOSE
        
        printf ("Najkrotsza scizka (algorytm Dijkstry, lista)\n");
        for (i = 0; i < iterations; i++)
        {
            oriented_graph_list.find_shortest_path_dijkstra (0);  
        }
    }

    if (algorithm == 5)
    {      
        OrientedAdjacencyList oriented_graph_list (nodes, edges);
        
        oriented_graph_list.generate (1, 10);     
#ifdef VERBOSE       
        oriented_graph_list.print ();
#endif // VERBOSE
        
        printf ("Najkrotsza scizka (algorytm Bellman-Ford, lista):\n");
        for (i = 0; i < iterations; i++)
        {
            oriented_graph_list.find_shortest_path_bellman_ford (0);   
        }
    }
    
////////////////////////////////////////////////////////////////////////////////    
#ifdef VERBOSE     
    printf ("Graf nieskierowany w postaci listy sasiedztwa:\n");
#endif // VERBOSE
    fflush (0);

    if (algorithm == 6)
    {           
        printf ("Drzewo rozpinajace (Kruskal, macierz)\n");
        for (i = 0; i < iterations; i++)
        {
            UnorientedAdjacencyList unoriented_graph_list (nodes, edges);
         
            unoriented_graph_list.generate (1, 10);    
#ifdef VERBOSE     
            unoriented_graph_list.print ();
#endif // VERBOSE
            unoriented_graph_list.get_spanning_tree_kruskal ();    
        }
    }
        
    if (algorithm == 7)
    {    
        printf ("Drzewo rozpinajace (Prim, lista)\n");
        for (i = 0; i < iterations; i++)
        {
            UnorientedAdjacencyList unoriented_graph_list (nodes, edges);
         
            unoriented_graph_list.generate (1, 10);    
#ifdef VERBOSE     
            unoriented_graph_list.print ();
#endif // VERBOSE
            unoriented_graph_list.get_spanning_tree_prim ();      
        }
    }    
    
#ifdef VERBOSE      
    printf ("\n\tDrzewo rozpinajace (Prim)\n");
#endif // VERBOSE
    unoriented_graph_list.get_spanning_tree_prim ();      
    fflush (0);
    
    return 0;
}
